package com.sky.mapper.user;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.pojo.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {

    @Select("select * from orders where number = #{number}")
    Orders getByNumber(String number);

    void insert(Orders orders);

    @Select("select * from orders o where order_time < #{time} and status = 1")
    List<Orders> getCheckPayStatusOrders(LocalDateTime time);

    @Update("update orders set status = #{status},pay_status = #{payStatus} where id = #{id}")
    int updateOrderPaySuccess(Orders orders);


    @Update("update orders set status = #{status},pay_status = #{payStatus},cancel_time = #{cancelTime},cancel_reason = #{cancelReason} where id = #{id}")
    int cancelOrder(Orders orders);

    Page<OrderVO> conditionSearch(OrdersPageQueryDTO dto);

    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);


    OrderStatisticsVO orderStatistics();
}
